c# binding add combobox with enum values

47

c# binding add combobox with enum values -

public class DataItem
{
    public MyEnum Value { get; set; }
    public string Text { get; set; }
}

this.comboBox1.DataSource = Enum.GetValues(typeof(MyEnum)).Cast<MyEnum>()
                                .Select(x => new DataItem() { Value = x, Text = x.ToString() })
                                .ToList();
this.comboBox1.ValueMember = "Value";
this.comboBox1.DisplayMember = "Text";

this.comboBox1.DataBindings.Add(
    new Binding("SelectedValue", yourObjectToBind, "PropertyOfYourObject"));

Comments

Submit
0 Comments